package org.rabbitmq.test3;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.rabbitmq.utils.RabbitMqUtils;
import org.rabbitmq.utils.SleepUtils;

public class Work04 {

    public static final String TASK_QUEUE_NAME = "task";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明 接收消息
        DeliverCallback deliverCallback = (consumerTag, message) ->{
            SleepUtils.sleep(30);
            System.out.println("工作1"+new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };

        //取消消息时的回调
        CancelCallback cancelCallback = consumerTag ->{
            System.out.println("消息消费被中断");
        };
        channel.basicQos(7);
        System.out.println("C4接收时间长");
        //接收消息
        channel.basicConsume(TASK_QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
